Chapter 7 Functional differences
# Aggregate bundle-level GIFTs into the compound level
GIFTs_elements <- to.elements(genome_gifts, GIFT_db)
GIFTs_elements_filtered <- GIFTs_elements[rownames(GIFTs_elements) %in% genome_counts$genome, ]
GIFTs_elements_filtered <- as.data.frame(GIFTs_elements_filtered) %>%
select_if(~ !is.numeric(.) || sum(.) != 0)
elements <- GIFTs_elements_filtered %>%
as.data.frame()
# Aggregate element-level GIFTs into the function level
GIFTs_functions <- to.functions(GIFTs_elements_filtered, GIFT_db)
functions <- GIFTs_functions %>%
as.data.frame()
# Aggregate function-level GIFTs into overall Biosynthesis, Degradation and Structural GIFTs
GIFTs_domains <- to.domains(GIFTs_functions, GIFT_db)
domains <- GIFTs_domains %>%
as.data.frame()
# Get community-weighed average GIFTs per sample
GIFTs_elements_community <- to.community(GIFTs_elements_filtered, genome_counts %>% column_to_rownames(., "genome") %>% tss(), GIFT_db)
GIFTs_functions_community <- to.community(GIFTs_functions, genome_counts %>% column_to_rownames(., "genome") %>% tss(), GIFT_db)
GIFTs_domains_community <- to.community(GIFTs_domains, genome_counts %>% column_to_rownames(., "genome") %>% tss(), GIFT_db)7.1 Function level
GIFTs_functions_community %>%
as.data.frame() %>%
rownames_to_column(var="sample") %>%
pivot_longer(!sample,names_to="trait",values_to="gift") %>%
left_join(sample_metadata, by = join_by(sample == sample)) %>%
ggplot(aes(x=trait,y=sample,fill=gift)) +
geom_tile(colour="white", size=0.2)+
scale_fill_gradientn(colours=rev(c("#d53e4f", "#f46d43", "#fdae61", "#fee08b", "#e6f598", "#abdda4", "#ddf1da")))+
facet_grid(type ~ ., scales="free",space="free")7.1.1 GIFT test
GIFTs_functions_community_tt <- GIFTs_functions_community %>%
as.data.frame() %>%
rownames_to_column("sample") %>%
separate(sample, into = c("individual", "type"), sep = "\\.") %>%
pivot_longer(-c(individual, type), names_to = "trait", values_to = "value") %>%
group_by(trait) %>%
mutate(model_result = list(lmerTest::lmer(value ~ type + (1 | individual)))) %>%
ungroup() %>%
select(trait,model_result) %>%
unique() %>%
mutate(estimate = map_dbl(model_result, ~broom.mixed::tidy(.) %>% filter(term == "typefeces") %>% pull(estimate))) %>%
mutate(p_value = map_dbl(model_result, ~broom.mixed::tidy(.) %>% filter(term == "typefeces") %>% pull(p.value))) %>%
mutate(p_value_adj = p.adjust(p_value, method = "bonferroni")) %>%
left_join(GIFT_db %>% select(Code_function,Function) %>% unique(),by=join_by(trait==Code_function)) %>%
rename(id=trait,trait=Function) %>%
select(id,trait, estimate, p_value_adj)
GIFTs_functions_community_tt %>% tt() |>
style_tt(
i = which(GIFTs_functions_community_tt$estimate < 0 & GIFTs_functions_community_tt$p_value_adj < 0.05),
background = "#E5D5B1") |>
style_tt(
i = which(GIFTs_functions_community_tt$estimate > 0 & GIFTs_functions_community_tt$p_value_adj < 0.05),
background = "#B7BCCE")| id | trait | estimate | p_value_adj |
|---|---|---|---|
| B01 | Nucleic acid biosynthesis | -0.1239096120 | 0.0789632267 |
| B02 | Amino acid biosynthesis | -0.0804948274 | 1.0000000000 |
| B03 | Amino acid derivative biosynthesis | 0.0007016942 | 1.0000000000 |
| B04 | SCFA biosynthesis | -0.0816375152 | 0.2029465396 |
| B06 | Organic anion biosynthesis | -0.1260870825 | 0.0000726699 |
| B07 | Vitamin biosynthesis | -0.2291795852 | 0.0052439519 |
| B08 | Aromatic compound biosynthesis | -0.0427342818 | 1.0000000000 |
| B09 | Metallophore biosynthesis | 0.0218478800 | 0.0001954785 |
| B10 | Antibiotic biosynthesis | 0.0147647263 | 0.0005469608 |
| D01 | Lipid degradation | 0.0169045716 | 1.0000000000 |
| D02 | Polysaccharide degradation | 0.1841580818 | 0.0385978704 |
| D03 | Sugar degradation | 0.1349845189 | 0.0579566482 |
| D05 | Amino acid degradation | -0.0585858599 | 0.0853328157 |
| D06 | Nitrogen compound degradation | 0.0599820612 | 0.0085217728 |
| D07 | Alcohol degradation | -0.0296476599 | 1.0000000000 |
| D08 | Xenobiotic degradation | 0.0127910880 | 0.0758716036 |
| D09 | Antibiotic degradation | -0.0300866841 | 1.0000000000 |
| S01 | Cellular structure | -0.0713222899 | 1.0000000000 |
| S02 | Appendages | -0.0128764080 | 1.0000000000 |
| S03 | Spore | 0.0227568436 | 1.0000000000 |
7.1.2 GIFT test visualisation
GIFTs_functions_community %>%
as.data.frame() %>%
rownames_to_column("sample") %>%
separate(sample, into = c("individual", "type"), sep = "\\.") %>%
pivot_longer(-c(individual, type), names_to = "trait", values_to = "value") %>%
mutate(trait = case_when(
trait %in% GIFT_db$Code_function ~ GIFT_db$Function[match(trait, GIFT_db$Code_function)],
TRUE ~ trait
)) %>%
mutate(trait=factor(trait,levels=unique(GIFT_db$Function))) %>%
ggplot(aes(x=value, y=type, group=type, fill=type, color=type)) +
geom_boxplot() +
scale_color_manual(name="Sample type",
breaks=c("cloaca","feces"),
labels=c("Cloaca","Faeces"),
values=c("#e5bd5b", "#6b7398")) +
scale_fill_manual(name="Sample type",
breaks=c("cloaca","feces"),
labels=c("Cloaca","Faeces"),
values=c("#e5bd5b50", "#6b739850")) +
facet_grid(trait ~ ., space="free", scales="free") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
strip.text.y = element_text(angle = 0)) +
labs(y="Traits",x="Metabolic capacity index")7.2 Element level
GIFTs_elements_community %>%
as.data.frame() %>%
rownames_to_column(var="sample") %>%
pivot_longer(!sample,names_to="trait",values_to="gift") %>%
left_join(sample_metadata, by = join_by(sample == sample)) %>%
mutate(functionid = substr(trait, 1, 3)) %>%
mutate(trait = case_when(
trait %in% GIFT_db$Code_element ~ GIFT_db$Element[match(trait, GIFT_db$Code_element)],
TRUE ~ trait
)) %>%
mutate(functionid = case_when(
functionid %in% GIFT_db$Code_function ~ GIFT_db$Function[match(functionid, GIFT_db$Code_function)],
TRUE ~ functionid
)) %>%
mutate(trait=factor(trait,levels=unique(GIFT_db$Element))) %>%
mutate(functionid=factor(functionid,levels=unique(GIFT_db$Function))) %>%
ggplot(aes(x=sample,y=trait,fill=gift)) +
geom_tile(colour="white", linewidth=0.2)+
scale_fill_gradientn(colours=rev(c("#d53e4f", "#f46d43", "#fdae61", "#fee08b", "#e6f598", "#abdda4", "#ddf1da")))+
facet_grid(functionid ~ type, scales="free",space="free") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
strip.text.y = element_text(angle = 0)) +
labs(y="Traits",x="Samples",fill="GIFT")7.2.1 GIFT test
GIFTs_elements_community_tt <- GIFTs_elements_community %>%
as.data.frame() %>%
rownames_to_column("sample") %>%
separate(sample, into = c("individual", "type"), sep = "\\.") %>%
pivot_longer(-c(individual, type), names_to = "trait", values_to = "value") %>%
group_by(trait) %>%
mutate(model_result = list(lmerTest::lmer(value ~ type + (1 | individual)))) %>%
ungroup() %>%
select(trait,model_result) %>%
unique() %>%
mutate(estimate = map_dbl(model_result, ~broom.mixed::tidy(.) %>% filter(term == "typefeces") %>% pull(estimate))) %>%
mutate(p_value = map_dbl(model_result, ~broom.mixed::tidy(.) %>% filter(term == "typefeces") %>% pull(p.value))) %>%
mutate(p_value_adj = p.adjust(p_value, method = "bonferroni")) %>%
left_join(GIFT_db %>% select(Code_element,Element) %>% unique(),by=join_by(trait==Code_element)) %>%
rename(id=trait,trait=Element) %>%
select(id,trait, estimate, p_value_adj)
GIFTs_elements_community_tt %>% tt() |>
style_tt(
i = which(GIFTs_elements_community_tt$estimate < 0 & GIFTs_elements_community_tt$p_value_adj < 0.05),
background = "#E5D5B1") |>
style_tt(
i = which(GIFTs_elements_community_tt$estimate > 0 & GIFTs_elements_community_tt$p_value_adj < 0.05),
background = "#B7BCCE")| id | trait | estimate | p_value_adj |
|---|---|---|---|
| B0101 | Inosinic acid (IMP) | -0.126554932 | 8.709660e-03 |
| B0102 | Uridylic acid (UMP) | -0.074805024 | 1.000000e+00 |
| B0103 | UDP/UTP | -0.059803944 | 1.860094e-03 |
| B0104 | CDP/CTP | -0.225068834 | 4.598925e-01 |
| B0105 | ADP/ATP | -0.177480115 | 9.505044e-02 |
| B0106 | GDP/GTP | -0.079744822 | 1.000000e+00 |
| B0204 | Serine | -0.354858798 | 8.260433e-03 |
| B0205 | Threonine | -0.043036376 | 1.000000e+00 |
| B0206 | Cysteine | -0.018948122 | 1.000000e+00 |
| B0207 | Methionine | -0.045492617 | 1.000000e+00 |
| B0208 | Valine | -0.067754019 | 1.000000e+00 |
| B0209 | Isoleucine | -0.098451818 | 1.000000e+00 |
| B0210 | Leucine | -0.252634408 | 3.014443e-02 |
| B0211 | Lysine | -0.154928290 | 3.569786e-03 |
| B0212 | Arginine | -0.074937843 | 1.000000e+00 |
| B0213 | Proline | 0.072061854 | 1.000000e+00 |
| B0214 | Glutamate | -0.163945870 | 1.000000e+00 |
| B0215 | Histidine | -0.110770104 | 1.000000e+00 |
| B0216 | Tryptophan | -0.155321081 | 1.000000e+00 |
| B0217 | Phenylalanine | 0.090352396 | 3.522676e-02 |
| B0218 | Tyrosine | -0.054738887 | 1.000000e+00 |
| B0219 | GABA | 0.008944378 | 2.802439e-03 |
| B0220 | Beta-alanine | 0.052000478 | 1.000000e+00 |
| B0221 | Ornithine | -0.016921240 | 1.000000e+00 |
| B0302 | Betaine | 0.006282259 | 1.040129e-01 |
| B0303 | Ectoine | -0.061541292 | 1.000000e+00 |
| B0307 | Spermidine | 0.024558839 | 1.000000e+00 |
| B0309 | Putrescine | 0.022257358 | 7.703042e-03 |
| B0310 | Tryptamine | 0.006370743 | 1.000000e+00 |
| B0401 | Acetate | -0.072824075 | 1.000000e+00 |
| B0402 | Butyrate | -0.085591608 | 1.000000e+00 |
| B0403 | Propionate | -0.084124407 | 8.360457e-02 |
| B0601 | Succinate | -0.218863703 | 2.909610e-03 |
| B0602 | Fumarate | -0.152091312 | 9.695782e-03 |
| B0603 | Citrate | -0.113302238 | 1.046572e-01 |
| B0604 | L-lactate | 0.173827523 | 1.000000e+00 |
| B0605 | D-lactate | 0.117659039 | 1.000000e+00 |
| B0701 | Thiamine (B1) | -0.423569978 | 1.506470e-03 |
| B0702 | Riboflavin (B2) | -0.123343077 | 1.000000e+00 |
| B0703 | Niacin (B3) | -0.132343743 | 3.309870e-04 |
| B0704 | Pantothenate (B5) | -0.161771233 | 1.000000e+00 |
| B0705 | Pyridoxal-P (B6) | -0.157391209 | 1.000000e+00 |
| B0706 | Biotin (B7) | -0.465333529 | 1.170382e-03 |
| B0707 | Tetrahydrofolate (B9) | -0.157663922 | 2.041897e-01 |
| B0708 | Cobalamin (B12) | -0.306856794 | 1.202664e-05 |
| B0709 | Tocopherol/tocotorienol (E) | 0.046795745 | 6.297584e-03 |
| B0710 | Phylloquinone (K1) | 0.003715408 | 1.000000e+00 |
| B0711 | Menaquinone (K2) | -0.085362182 | 9.658381e-02 |
| B0712 | Ubiquinone (Q10) | -0.033784932 | 1.332460e-04 |
| B0801 | Salicylate | 0.004296057 | 1.000000e+00 |
| B0802 | Gallate | -0.016400034 | 1.000000e+00 |
| B0803 | Chorismate | -0.160193050 | 5.298927e-01 |
| B0804 | Dipicolinate | -0.136859458 | 1.000000e+00 |
| B0805 | Indole-3-acetate | 0.031893097 | 1.000000e+00 |
| B0901 | Staphyloferrin | 0.030119095 | 3.151489e-03 |
| B0902 | Aerobactin | 0.004219423 | 1.000000e+00 |
| B0903 | Staphylopine | 0.024019936 | 4.654771e-02 |
| B1004 | Bacilysin | -0.018245005 | 8.344534e-02 |
| B1012 | Fosfomycin | 0.037752023 | 4.213150e-04 |
| B1014 | Kanosamine | 0.003484397 | 1.000000e+00 |
| B1028 | Pyocyanin | 0.031056273 | 2.227210e-04 |
| D0101 | Triglyceride | 0.058936892 | 5.062892e-03 |
| D0102 | Fatty acid | -0.015195375 | 1.000000e+00 |
| D0103 | Oleate | 0.013778887 | 1.000000e+00 |
| D0104 | Dicarboxylic acids | -0.031934437 | 1.000000e+00 |
| D0201 | Cellulose | 0.112847616 | 1.522662e-02 |
| D0202 | Xyloglucan | 0.157396459 | 1.248570e-01 |
| D0203 | Starch | 0.160575521 | 1.000000e+00 |
| D0204 | Chitin | 0.043775661 | 1.000000e+00 |
| D0205 | Pectin | 0.145232275 | 9.916554e-03 |
| D0206 | Alpha galactan | 0.311924825 | 1.000000e+00 |
| D0207 | Beta-galactan | 0.279649459 | 1.000000e+00 |
| D0208 | Mixed-Linkage glucans | 0.141291114 | 1.000000e+00 |
| D0209 | Xylans | 0.220702518 | 4.624543e-03 |
| D0210 | Beta-mannan | 0.178322073 | 4.991821e-02 |
| D0211 | Alpha-mannan | 0.108240476 | 6.183472e-05 |
| D0212 | Arabinan | 0.309047488 | 8.273962e-06 |
| D0213 | Mucin | 0.225049579 | 8.345230e-01 |
| D0301 | Lactose | 0.021559174 | 1.507361e-01 |
| D0302 | Sucrose | 0.174986075 | 2.201890e-02 |
| D0303 | D-Apiose | 0.001427278 | 1.000000e+00 |
| D0304 | D-Arabinose | 0.115589119 | 1.000000e+00 |
| D0305 | D-Mannose | -0.079588186 | 3.983501e-01 |
| D0306 | D-Xylose | 0.221369683 | 2.208707e-03 |
| D0307 | L-Fucose | 0.170884929 | 6.163796e-02 |
| D0308 | L-Rhamnose | 0.169830701 | 1.000000e+00 |
| D0309 | Galactose | 0.091292663 | 1.000000e+00 |
| D0310 | NeuAc | 0.190156475 | 1.000000e+00 |
| D0501 | Serine | -0.227261093 | 1.075226e-02 |
| D0502 | Threonine | -0.146130577 | 1.000000e+00 |
| D0503 | Cysteine | 0.011476506 | 3.580973e-04 |
| D0504 | Methionine | 0.002940103 | 1.000000e+00 |
| D0505 | Valine | -0.089366059 | 1.000000e+00 |
| D0506 | Isoleucine | -0.059930930 | 3.268242e-02 |
| D0507 | Leucine | -0.009430230 | 1.000000e+00 |
| D0508 | Lysine | 0.029159728 | 5.701031e-03 |
| D0509 | Arginine | 0.011052972 | 1.000000e+00 |
| D0510 | Proline | 0.021476918 | 1.000000e+00 |
| D0511 | Glutamate | -0.119388065 | 1.000000e+00 |
| D0512 | Histidine | -0.167185365 | 1.000000e+00 |
| D0513 | Tryptophan | -0.320056980 | 1.000000e+00 |
| D0516 | Beta-alanine | -0.177656539 | 1.000000e+00 |
| D0517 | Ornithine | 0.009547172 | 2.999024e-01 |
| D0518 | GABA | 0.016842120 | 1.000000e+00 |
| D0601 | Nitrate | -0.026422753 | 1.000000e+00 |
| D0602 | Urea | 0.142800526 | 1.265787e-04 |
| D0603 | Urate | 0.004540184 | 6.697284e-01 |
| D0604 | GlcNAc | 0.372879440 | 5.877157e-02 |
| D0606 | Allantoin | 0.051014205 | 3.766753e-01 |
| D0607 | Creatinine | 0.031711336 | 8.365380e-02 |
| D0609 | L-carnitine | 0.126172089 | 2.697109e-03 |
| D0610 | Methylamine | -0.054084816 | 1.000000e+00 |
| D0611 | Phenylethylamine | 0.004023910 | 1.000000e+00 |
| D0612 | Hypotaurine | 0.014167003 | 1.000000e+00 |
| D0613 | Taurine | 0.051963339 | 1.000000e+00 |
| D0701 | 2,3-Butanediol | 0.002997105 | 1.000000e+00 |
| D0702 | Ethanol | -0.144734706 | 1.000000e+00 |
| D0704 | Glycerol | 0.075558083 | 1.000000e+00 |
| D0705 | Propylene glycol | -0.029295774 | 1.000000e+00 |
| D0706 | Ethylene glycol | -0.211161601 | 4.261025e-01 |
| D0708 | Phytol | -0.071779249 | 3.627745e-03 |
| D0801 | Toluene | 0.001289127 | 1.000000e+00 |
| D0802 | Xylene | 0.001289127 | 1.000000e+00 |
| D0805 | Benzoate | 0.001083807 | 1.000000e+00 |
| D0807 | Catechol | 0.026325954 | 1.000000e+00 |
| D0815 | Phthalate | 0.004031937 | 1.000000e+00 |
| D0816 | Phenylacetate | 0.023697091 | 1.000000e+00 |
| D0817 | Trans-cinnamate | 0.041494948 | 9.945577e-04 |
| D0901 | Penicillin | -0.221818680 | 1.000000e+00 |
| D0902 | Carbapenem | 0.032819810 | 5.607652e-03 |
| D0903 | Cephalosporin | 0.006989472 | 5.131141e-02 |
| D0904 | Oxacillin | 0.005024446 | 9.111216e-01 |
| D0905 | Streptogramin | -0.186670929 | 1.000000e+00 |
| D0907 | Tetracycline | 0.398619606 | 4.510592e-03 |
| D0908 | Macrolide | -0.114003199 | 1.000000e+00 |
| D0910 | Chloramphenicol | -0.014452146 | 1.000000e+00 |
| D0911 | Lincosamide | -0.177288537 | 1.000000e+00 |
| S0101 | Peptidoglycan | -0.156833021 | 2.205558e-03 |
| S0103 | Teichoic acid | -0.092594984 | 1.000000e+00 |
| S0104 | Lipoteichoic acid | 0.073971060 | 1.000000e+00 |
| S0105 | Lipopolysaccharide | -0.038194406 | 1.000000e+00 |
| S0201 | Flagellum | -0.104812839 | 1.000000e+00 |
| S0202 | Pilus | 0.048414546 | 1.415631e-03 |
| S0301 | Spore | 0.022756844 | 1.000000e+00 |